package com.sq.partner.manager.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sq.partner.manager.dao.FacadeAppFormDao;
import com.sq.partner.manager.mybatis.model.FacadeAppForm;

/**
 * 投保单Dao
 * 
 * @author zhouxiuxiu
 *
 */
@Repository
public class FacadeAppFormDaoImpl extends BaseDaoImpl implements
        FacadeAppFormDao {

    /**
     * 添加投保单
     */
    @Override
    public void insertFacadeAppForm(FacadeAppForm facadeAppForm)
            throws Exception {
        this.add("insertFacadeAppForm", facadeAppForm);
    }

    /**
     * 取得投保单号
     */
    @Override
    public String queryNewAppNo() throws SQLException {
        return (String) this.query("queryNewAppNo", "CJ");
    }

    /**
     * 修改投保单
     */
    @Override
    public void updateFacadeAppFormNotNull(FacadeAppForm facadeAppForm)
            throws Exception {
        this.update("updateFacadeAppFormNotNull", facadeAppForm);
    }

    /**
     * 根据暂存单号和投保状态取得投保单信息
     * 
     * @param facadeAppForm
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<FacadeAppForm> selectFacadeAppFormList(
            FacadeAppForm facadeAppForm) throws Exception {
        return (List<FacadeAppForm>) this.queryList("queryFacadeAppFormByMap2",
                facadeAppForm);
    }

    /**
     * 根据暂存单号查询个人投保信息
     * 
     * @param stagNo
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @Override
    public FacadeAppForm queryNLifeSingleFacadeAppFormByStagNo(String stagNo)
            throws Exception {
        List<FacadeAppForm> facadeAppForms = (List<FacadeAppForm>) queryList(
                "queryNLifeSingleAppFormByStagNo", stagNo);
        FacadeAppForm facadeAppForm = null;
        if (facadeAppForms != null) {
            facadeAppForm = facadeAppForms.get(0);
        }
        return facadeAppForm;
    }

    /**
     * 查询投保单信息
     * 
     * @param appNo
     * @return
     * @throws Exception
     */
    @Override
    public FacadeAppForm queryFacadeAppFormByAppNo(String appNo)
            throws Exception {
        return (FacadeAppForm) this.query("queryFacadeAppFormById", appNo);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<FacadeAppForm> selectFacadeAppFormListPayByNlife(
            FacadeAppForm facadeAppForm) throws Exception {
        return (List<FacadeAppForm>) this.queryList(
                "queryFacadeAppFormByNlifeByMap2", facadeAppForm);
    }
    
    /**
     * 查询暂存单下的投保单数
     * @param stagNo
     * @return
     * @throws Exception
     */
    @Override
    public int queryAppCountByStagNo(String stagNo) throws Exception {
        return (Integer) this.query("queryAppCountByStagNo", stagNo);
    }
    
    /**
     * 根据投保单号删除投保单
     * @param appNo
     * @return
     * @throws SQLException
     */
    @Override
    public boolean deleteAppFormByAppNo(String appNo) throws Exception {
        return this.delete("deleteAppFormByAppNo", appNo);
    }
    
    /**
     * 支付完成后更新投保单表状态为12 已支付 20190425 helina
     * @param facadeAppForm
     * @return
     * @throws Exception
     */
	@Override
	public boolean updateFacadeAppFormStatus12(FacadeAppForm facadeAppForm)
			throws Exception {
		return this.update("updateAppFormStatus12", facadeAppForm);
	}
	
	/**
	 * 根据方案，投保起止期，证件类型，姓名，身份证号码查询已支付投保单数量
	 *
	 * @param  map
	 * @return
	 * @throws Exception
	 */
	@Override
	public Integer queryExistInsuredCount(Map<String, Object> map) throws Exception {
		return (Integer) this.query("queryInsuredCount", map);
	}

    /**
     * 根据方案，投保起止期，证件类型，姓名，身份证号码查询已支付投保单 批量
     *
     * @param  map
     * @return
     * @throws Exception
     */
    @Override
    public Integer queryExistInsuredCountBatch(Map<String, Object> map) throws Exception {
        return (Integer) this.query("queryInsuredCountBatch", map);
    }
}
